package pers.jason.wppm.auth.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import pers.jason.wppm.api.support.ResultView;
import pers.jason.wppm.auth.api.dto.AuthenticationCondition;
import pers.jason.wppm.auth.api.dto.UserInsertCondition;
import pers.jason.wppm.auth.api.dto.UserQueryConditionPageable;
import pers.jason.wppm.auth.api.dto.UserUpdateCondition;
import pers.jason.wppm.auth.log.ControllerLog;
import pers.jason.wppm.auth.web.service.UserService;


/**
 * 
 * @author Jason
 * @Date 2018-10-25 14:55
 *
 * 用户服务接口
 */
@RestController
@RequestMapping("user")
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * @param id
	 * @return
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "getUserInfoById(id) 通过ID获取用户详细信息")
	public ResultView getUserInfoById(@PathVariable("id") String id) {
		return userService.getUserInfoById(id); 
	}

	/**
	 * 登录调用
	 * @param authenticationCondition
	 * @return
	 */
	@PostMapping
	@ControllerLog(description = "安全框架认证请求")
	@ApiOperation(value = "findUserForLogin(AuthenticationCondition authenticationCondition) 认证，使用登录名获取用户信息")
	public ResultView findUserForLogin(AuthenticationCondition authenticationCondition) {
		ResultView resultView = userService.findUserForLogin(authenticationCondition);
		return resultView;
	}

	@GetMapping("list")
	@ApiOperation(value = "queryUserList(UserQueryConditionPageable userPageable) 条件查询用户列表")
	public ResultView queryUserList(@Validated UserQueryConditionPageable userPageable) {
		return userService.queryUserList(userPageable);
	}

	@PutMapping("/")
	@ApiOperation(value = "updateUserInfo(user) 修改用户基本信息（不包含登录名和密码）")
	public ResultView updateUserInfo(@Validated UserUpdateCondition userUpdateCondition) {
		// TODO Auto-generated method stub
		return userService.updateUserInfo(userUpdateCondition);
	}

	@DeleteMapping("/{id}")
	@ApiOperation(value = "deleteUser(id) 软删除用户")
	public ResultView deleteUser(@PathVariable("id") String id) {
		// TODO Auto-generated method stub
		return userService.deleteUser(id);
	}

	@PostMapping("/user")
	@ApiOperation(value = "registUserByMobile(user) 手机注册用户")
	public ResultView registUserByMobile(@Validated UserInsertCondition userInsertCondition) {
		return userService.registUserByMobile(userInsertCondition);
	}
	
}
